//
// Created by Administrator on 2022/2/19.
//

#ifndef CPP_LEARNING_MATCH_H
#define CPP_LEARNING_MATCH_H
#include <string.h>
/**
 * 暴力匹配算法 1
 */
int match_1(char* P, char* T){
    int n = strlen(T) , i = 0;
    int m = strlen(P) , j = 0;

    while (j<m && i<n){
        if(T[i] == P[j]){
            i++;
            j++;
        }else{
            i -= j-1;
            j = 0;
        }
    }
    return i-j;
}

/**
 * 暴力匹配算法 2
 */
int match_2(char* P, char* T){
    int n = strlen(T) , i = 0;
    int m = strlen(P) , j ;

    for(i = 0; i < n-m+1; i++){
        for(j=0; j<m; j++){
            if(T[i+j] != P[j]) break;
        }

        if(m<=j) break;
    }
    return i;
}

#endif //CPP_LEARNING_MATCH_H
